package com.define.ssh.action.monitoring;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.define.ssh.action.admin.BaseAdminAction;
import com.define.ssh.model.MWarnDetail;
import com.define.ssh.model.MWarnMember;
import com.define.ssh.model.MWarnScope;
import com.define.ssh.model.MWarnTarget;
import com.define.ssh.model.TbLog;
import com.define.ssh.model.Terminal;
import com.define.ssh.model.UserInfo;
import com.define.ssh.service.MWarnDetailService;
import com.define.ssh.service.MWarnScopeService;
import com.define.ssh.service.TbLogService;
import com.define.ssh.util.SystemUtil;
import com.define.ssh.util.Pager.Order;


/**
 *  
 * 
 */
@ParentPackage("admin")
public class ResultsAction extends BaseAdminAction {

	/** 页面传递参数过来 */
	protected int pageSize;
	protected int pageNum;

	
	
	@Resource(name = "mwarnDetailServiceImpl")
	private MWarnDetailService  mwarnDetailService;
	/**
	 * 列表页
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() {
		
		
		try {
			
			HashMap<String, Object> searchMap = new HashMap<String, Object>();
			pager.setOrder(Order.desc);
			pager.setOrderBy("updatetime");
			pager.setSearchMap(searchMap);
			pager =mwarnDetailService.findPager(pager);
			
			List<MWarnDetail> list= (List<MWarnDetail>) pager.getResult();
			for (MWarnDetail mWarnDetail : list) {
				
			/*	 DetachedCriteria dt = DetachedCriteria.forClass(MWarnScope.class);	
				 dt.add(Restrictions.eq("stype",mWarnDetail.getStype()));
				 List  mdlist=mwarnDetailService.findByCriteria(dt);
				 if(mdlist!=null&&mdlist.size()>0){
					 MWarnScope mwarnScope=(MWarnScope)mdlist.get(0);
					 mWarnDetail.setSname(mwarnScope.getSname());
					 mWarnDetail.setDescribe(mwarnScope.getDescribe());
				 }*/
				
				DetachedCriteria dt = DetachedCriteria.forClass(MWarnTarget.class);	
				 dt.add(Restrictions.eq("targetid",mWarnDetail.getTargetid()));
				 List  mdlist=mwarnDetailService.findByCriteria(dt);
				 if(mdlist!=null&&mdlist.size()>0){
					 MWarnTarget mw=(MWarnTarget)mdlist.get(0);
					 mWarnDetail.setSname(mw.getSname());
					 mWarnDetail.setDescribe(mw.getSdetail());
					 mWarnDetail.setWarnthreshold(mw.getWarnthreshold().toString());
					
				 }
				 
				 DetachedCriteria dt2 = DetachedCriteria.forClass(Terminal.class);	
				 dt2.add(Restrictions.eq("netid",Long.valueOf(mWarnDetail.getNetid())));
				 List  terlist=mwarnDetailService.findByCriteria(dt2);
				 if(terlist!=null&&terlist.size()>0){
					 Terminal terminal=(Terminal)terlist.get(0);
					 mWarnDetail.setPname(terminal.getName());
					
				 }
				 
			}
			
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		return "results";
	}

}
